<template>
  <div>
    <el-card class="!border-none relative el-card-client" shadow="never">
      <template #header>
        <el-row :gutter="10">
          <el-col :span="3">
            <el-input
              class="input_style"
              v-model="queryParams.title"
              clearable
              placeholder="请输入标题"
            />
          </el-col>
          <el-col :span="3">
            <el-date-picker
              v-model="queryParams.create_time"
              class="input_time_style"
              type="date"
              placeholder="请选择日期"
              clearable
              format="YYYY-MM-DD HH:mm:ss"
              @change="updateTime"
            />
          </el-col>
          <el-col :span="3">
            <el-select
              v-model="queryParams.type"
              clearable
              class="input_style"
              placeholder="请选择类型"
            >
              <el-option
                v-for="(item, index) in dictData.fk_type"
                :key="index"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-col>
          <el-col :span="3">
            <el-select
              v-model="queryParams.status"
              clearable
              class="input_style"
              placeholder="请选择状态"
            >
              <el-option
                v-for="(item, index) in dictData.fk_status"
                :key="index"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-col>
          <el-col :span="10">
            <el-button
              @click="getLists"
              color="#63ccba"
              type="primary"
              class="btn_style mr_10"
            >
              <template #icon>
                <el-icon style="color: #fff">
                  <Search />
                </el-icon>
              </template>
              搜索
            </el-button>
            <el-button @click="resetParams" plain class="mr_10">
              <template #icon>
                <icon name="el-icon-Refresh" />
              </template>
              重置
            </el-button>
          </el-col>
          <!-- <el-col :span="2" class="flex justify-end">
            <move-button></move-button>
          </el-col> -->
        </el-row>
      </template>
      <div>
        <el-table
          :data="pager.lists"
          border
          @selection-change="handleSelectionChange"
          v-loading="pager.loading"
          stripe
          height="calc(100vh - 14rem)"
        >
          <el-table-column label="标题" prop="title" show-overflow-tooltip />
          <el-table-column label="会员账号" prop="uid" show-overflow-tooltip />
          <el-table-column label="反馈状态" prop="type">
            <template #default="{ row }">
              <dict-value :options="dictData.fk_type" :value="row.type" />
            </template>
          </el-table-column>
          <el-table-column
            label="反馈类型"
            prop="mobile"
            show-overflow-tooltip
          />
          <el-table-column label="提交时间" prop="status">
            <template #default="{ row }">
              <dict-value :options="dictData.fk_status" :value="row.status" />
            </template>
          </el-table-column>
          <el-table-column label="联系方式" prop="create_time">
            <template #default="{ row }">
              <span>
                {{
                  row.create_time
                    ? timeFormat(row.create_time, "yyyy-mm-dd hh:MM:ss")
                    : ""
                }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" fixed="right">
            <template #default="{ row }">
              <el-button
                v-perms="['member.feedback/edit']"
                type="primary"
                link
                @click="handleEdit(row)"
                >编辑</el-button
              >
              <el-button
                v-perms="['member.feedback/edit']"
                type="danger"
                link
                @click="handleDelete(row.id)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="flex mt-4">
        <pagination v-model="pager" @change="getLists" class="position" />
      </div>
    </el-card>
    <edit-popup
      v-if="showEdit"
      ref="editRef"
      :dict-data="dictData"
      @success="getLists"
      @close="showEdit = false"
    />
  </div>
</template>

<script lang="ts" setup name="feedbackLists">
import { usePaging } from "@/hooks/usePaging";
import { useDictData } from "@/hooks/useDictOptions";
import { apiFeedbackLists, apiFeedbackDelete } from "@/api/feedback";
import { timeFormat } from "@/utils/util";
import feedback from "@/utils/feedback";
import EditPopup from "./edit.vue";
import moveButton from "@/components/moveButton/index.vue";

const editRef = shallowRef<InstanceType<typeof EditPopup>>();
//搜索框   暂时
const value = ref("");

// 是否显示编辑框
const showEdit = ref(false);

// 查询条件
const queryParams = reactive({
  title: "",
  type: "",
  status: "",
  create_time: "",
});
//修改时间格式
const updateTime = (time: number) => {
  queryParams.create_time = timeFormat(time, "yyyy-mm-dd hh:MM:ss");
};
// 选中数据
const selectData = ref<any[]>([]);

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
  selectData.value = val.map(({ id }) => id);
};

// 获取字典数据
const { dictData } = useDictData("fk_type,fk_status");

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
  fetchFun: apiFeedbackLists,
  params: queryParams,
});

// 添加
const handleAdd = async () => {
  showEdit.value = true;
  await nextTick();
  editRef.value?.open("add");
};

// 编辑
const handleEdit = async (data: any) => {
  showEdit.value = true;
  await nextTick();
  editRef.value?.open("edit");
  editRef.value?.setFormData(data);
};

// 删除
const handleDelete = async (id: number | any[]) => {
  await feedback.confirm("确定要删除？");
  await apiFeedbackDelete({ id });
  getLists();
};

getLists();
</script>
<style lang="scss" scoped>
.flex {
  display: flex !important;
}

.btn_style {
  color: #fff;
}

.m_0 {
  margin: 0;
}

.mr_10 {
  margin-right: 0.63rem;
}
</style>
